package com.linln.admin.filter;

import cn.hutool.core.util.ObjectUtil;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Repeatable 过滤器
 */
public class RepeatableFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String contentType = request.getContentType();
        if (ObjectUtil.isNotNull(contentType)){
            if (!contentType.contains("form")){
                RepeatedlyRequestWrapper requestWrapper = new RepeatedlyRequestWrapper(request);
                try {
                    filterChain.doFilter(requestWrapper, servletResponse);
                } catch (Exception ex) {
                }
            }else{
                filterChain.doFilter(request, servletResponse);
            }
        }else{
            filterChain.doFilter(request, servletResponse);
        }
    }
}
